難得發問並自解
轉成技術文章, 分享給大家, 感謝各位邦友幫忙!
說明:
InternetExplorer.Application
, 跳過EDGE不囉嗦! 上SOURCE CODE
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace IE.NET
{
internal class Program
{
//呼叫 WIN 元件取得螢幕大小
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int screensize);
const int SM_CXSCREEN = 0;
const int SM_CYSCREEN = 1;
//主程式
static void Main(string[] args)
{
//首頁
string StartURL = "http://IP/XXXX.asp";
//讓第三方傳參數呼叫, 帶入所需開啟的URL
if (args.Length > 0)
{
StartURL = args[0];
//如果URL很長要組合起來
if (args.Length > 1)
{
for (int i = 1; i < args.Length; i++)
{
StartURL = StartURL + "%20" + args[i];
}
}
}
//使用 GetSystemMetrics 取得螢幕大小
double wWidth = GetSystemMetrics(SM_CXSCREEN);
double wHeight = GetSystemMetrics(SM_CYSCREEN);
// 使用 GetTypeFromProgID 呼叫IE
var MemberAccess = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase;
var type = Type.GetTypeFromProgID("InternetExplorer.Application");
var ie = Activator.CreateInstance(type);
//設定IE視窗全螢幕
ie.GetType().InvokeMember("Visible", MemberAccess | BindingFlags.SetProperty, null, ie, new object[1] { true });
ie.GetType().InvokeMember("Top", MemberAccess | BindingFlags.SetProperty, null, ie, new object[1] { 0 });
ie.GetType().InvokeMember("Left", MemberAccess | BindingFlags.SetProperty, null, ie, new object[1] { 0 });
ie.GetType().InvokeMember("Height", MemberAccess | BindingFlags.SetProperty, null, ie, new object[1] { wHeight });
ie.GetType().InvokeMember("Width", MemberAccess | BindingFlags.SetProperty, null, ie, new object[1] { wWidth });
ie.GetType().InvokeMember("Navigate", MemberAccess | BindingFlags.InvokeMethod, null, ie, new object[] { StartURL });
}
}
}
感謝多位邦友幫幫忙!
提供很多方向!
謝謝!
參考:
https://welkingunther.pixnet.net/blog/post/26821658
https://blog.darkthread.net/blog/run-iexplore-in-win11/